package cn.singno.springBoot.demo.ch16_mvc;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest")
public class DemoRestController {

	@RequestMapping(value="/getjson" , produces="application/json;charset=UTF-8")
	public DemoObj getjson(DemoObj obj, HttpServletRequest request){
		return new DemoObj(obj.getId()+1, obj.getName() + "yy");
	}
	
	@RequestMapping(value="/getxml" , produces="application/xml;charset=UTF-8")
	public DemoObj getxml(DemoObj obj, HttpServletRequest request){
		return new DemoObj(obj.getId()+1, obj.getName() + "yy");
	}
	
	@RequestMapping(value="/getjson2")
	public DemoObj getjson2(DemoObj obj, HttpServletRequest request){
		return new DemoObj(obj.getId()+1, obj.getName() + "yy");
	}
	
	@RequestMapping(value="/getxml2")
	public DemoObj getxml2(DemoObj obj, HttpServletRequest request){
		return new DemoObj(obj.getId()+1, obj.getName() + "yy");
	}
	
	@RequestMapping(value="/exception")
	public String exception(@ModelAttribute("msg") String msg){
		throw new IllegalArgumentException("非常抱歉，参数有误：" + msg);
	}
}
